<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">
	
	<a4j:form id="orderQueryForm" styleClass="trn_form">
		
		<a4j:outputPanel id="msgContainer" ajaxRendered="true">
				<h:messages globalOnly="false" errorClass="msgError" styleClass="message" infoClass="msgInfo" />
			</a4j:outputPanel>
		<a4j:outputPanel id="orderQueryHeadPanel">
			<div id="Form_Table">
				<div id="Form_Row">
					<div class="form_fields">
						<s:label for="orQuerySupplier">Proveedor:</s:label>
						<h:selectOneMenu 
							styleClass="input"
							converter="#{supplierConverter}"
							value="#{trnPurchaseOrder.orderQueryHead.supplierData}"
							id="orQuerySupplier" >
							<a4j:support event="onchange" />
							<s:selectItems 
								value="#{withinHolder.supplierList()}" 
								var="supp"
								label="#{convertAssist.getSupplierName(supp.id)}"
								noSelectionLabel="Proveedor">
							</s:selectItems>
						</h:selectOneMenu>
						<div id="orQuerySupplierMsg" class="inactiveMsg"></div>
					</div>
					<div class="form_fields">
						<s:label for="orQueryStatus">Estado:</s:label>
						<h:selectOneMenu
							styleClass="input"
							value="#{trnPurchaseOrder.orderQueryHead.status}"
							id="orQueryStatus" >
							<a4j:support event="onchange" />
							<f:selectItem itemValue=""/>
							<f:selectItem itemLabel="PENDIENTE" itemValue="PEND" />
							<f:selectItem itemLabel="CONFIRMADO" itemValue="CONF"/>
							<f:selectItem itemLabel="ANULADO" itemValue="ANUL"/>
							<a4j:support event="onblur" />
						</h:selectOneMenu>
						<div id="orQueryStatusMsg" class="inactiveMsg"></div>
					</div>
					<div class="form_fields">
						<s:label for="orQueryOrderDate">Fecha Pedido:</s:label>
						<rich:calendar
							inputClass="input"
							id="orQueryOrderDate"
							value="#{trnPurchaseOrder.orderQueryHead.orderDate}" 
							datePattern="dd/MM/yy"
							buttonClass="field_btn"/>
						<a4j:commandButton
								action="#{trnPurchaseOrder.retrieveFilteredOrders()}"
								id="orQuerySearchBtn"
								value="Buscar" 
								reRender="orderQueryForm, orderQueryHeadGridPanel"
								styleClass="button"
								style="position:relative; left:10px; padding-bottom:4px; bottom:7px;"
								/>
						<div id="orQuerySupplierMsg" class="inactiveMsg"></div>
					</div>
				</div>
			</div>				
		</a4j:outputPanel>
		<a4j:outputPanel id="orderQueryHeadGridPanel">	
				<rich:datascroller align="center" for="orderQueryHeadGrid"
						maxPages="15" page="#{trnPurchaseOrder.scrollerPage}"
						renderIfSinglePage="false" />			   			
				<div style="clear: both;" />
				<rich:panel styleClass="table_add" rendered="#{not empty trnPurchaseOrder.allOrderQueryHead}">
					<rich:dataTable id="orderQueryHeadGrid"
						var="orderHead" rows="10"
						value="#{trnPurchaseOrder.allOrderQueryHead}"
						rendered="#{not empty trnPurchaseOrder.allOrderQueryHead}"
						rowClasses="rvgRowOne,rvgRowTwo"
						style="align:center;">
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Proveedor" /></f:facet>
							<h:outputText value="#{convertAssist.getSupplierName(orderHead.idSupplier)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Nro. Pedido" /></f:facet>
							<h:outputText value="#{orderHead.orderNumber}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Fecha. Pedido" /></f:facet>
							<h:outputText value="#{orderHead.orderDate}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Tipo Compra" /></f:facet>
							<h:outputText value="#{convertAssist.getRefDetDescrip(orderHead.buyType)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Cond. Compra" /></f:facet>
							<h:outputText value="#{convertAssist.getBuyConditionDesc(orderHead.buyCondition)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Fecha Entrega" /></f:facet>
							<h:outputText value="#{orderHead.deliveryDate}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Moneda" /></f:facet>
							<h:outputText value="#{convertAssist.getCurrencyDescById(orderHead.currency)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Total Pedido" /></f:facet>
							<h:outputText value="#{orderHead.orderTotal}" />
						</rich:column>
						<rich:column>
							<f:facet name="header"><h:outputText value="Estado" /></f:facet>
							<h:outputText value="#{orderHead.status}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Detalle" /></f:facet>
							<a4j:commandLink id="viewOrderQueryDet"  
							    action="#{trnPurchaseOrder.retrieveOrderDet(orderHead.id, 'QUERY')}"
								oncomplete="#{rich:component('modalOrderQueryDet')}.show()"
								reRender="modalOrderQueryDet"
								immediate="true">
	
								<h:graphicImage id="viewOrderQueryDetEditImg" url="/img/icons/database_table.png"
									styleClass="actionsImages" />
							</a4j:commandLink>
							<rich:toolTip value="Ver Detalle" for="viewDet" />
						</rich:column>
		
					</rich:dataTable>
				</rich:panel>
			</a4j:outputPanel>
			<a4j:commandLink
					id="orderQueryCloseBtn"
					styleClass="button"
					onclick="#{rich:component('OrderQueryCloseModalPanel')}.show()" 
					style="position:relative; float:right; right:15px; margin-top:15px;">
					<h:graphicImage value="/img/icons/close.png"/>
			</a4j:commandLink>
	</a4j:form>
	
	<rich:modalPanel  id="OrderQueryCloseModalPanel"
			resizeable="false" autosized="true" moveable="false" style="border:2px solid #6FADDF">
			<a4j:form>
			<div class="globalMessage">
				<h:outputText value="Esta seguro que desea cancelar la operacion?" />
			</div>
			<s:decorate template="/layout/displayButton.xhtml" styleClass="trn_button_form" style="width:270px; margin-top:0px; margin-left:auto;">
				<a4j:commandButton
					action="#{trnPurchaseOrder.cleanQuery()}"
					value="Aceptar" 
					id="OrderQueryAcceptClose"
					reRender="orderQueryForm"
					oncomplete="#{rich:component('OrderQueryCloseModalPanel')}.hide();#{rich:component('modalOrderQuery')}.hide();"
					styleClass="button" />
				<rich:spacer width="20px" />
				<a4j:commandButton value="Cancelar" id="OrderQueryCancelClose"
					onclick="#{rich:component('OrderQueryCloseModalPanel')}.hide()"
					styleClass="button" />
			</s:decorate>
			</a4j:form>
		</rich:modalPanel>
	
	<rich:modalPanel  id="modalOrderQueryDet"  minwidth="800" minheight="400" 
		resizeable="false" autosized="true" top="30">
		<f:facet name="header">
			<h:panelGroup>
				<h:outputText value="Detalle del Pedido" />
				</h:panelGroup>
		</f:facet>
		<f:facet name="controls">
			<h:panelGroup>
				<h:graphicImage value="/img/close.png" style="cursor:pointer"
					id="modalOrderQueryDetHide" />
				<rich:componentControl for="modalOrderQueryDet"
					attachTo="modalOrderQueryDetHide" operation="hide" event="onclick" />
			</h:panelGroup>
		</f:facet>
			<rich:panel styleClass="table_add" rendered="#{not empty trnPurchaseOrder.allOrderQueryDet}">
				<rich:dataTable id="orderQueryDetGrid"
						var="orderDet" rows="10"
						value="#{trnPurchaseOrder.allOrderQueryDet}"
						rendered="#{not empty trnPurchaseOrder.allOrderQueryDet}"
						rowClasses="rvgRowOne,rvgRowTwo"
						style="align:center;">

						<rich:column>
							<f:facet name="header"><h:outputText value="Item" /></f:facet>
							<h:outputText value="#{orderDet.item}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Insumo" /></f:facet>
							<h:outputText value="#{convertAssist.getSupplyDesc(orderDet.supply)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Cantidad" /></f:facet>
							<h:outputText value="#{orderDet.quantity}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Costo" /></f:facet>
							<h:outputText value="#{orderDet.grossCost}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Descuento" /></f:facet>
							<h:outputText value="#{orderDet.discount}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Recargo" /></f:facet>
							<h:outputText value="#{orderDet.charge}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="IVA" /></f:facet>
							<h:outputText value="#{convertAssist.getTaxDesc(orderDet.tax)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Gravadas" /></f:facet>
							<h:outputText value="#{orderDet.taxedTotal}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Exentas" /></f:facet>
							<h:outputText value="#{orderDet.exemptTotal}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Total" /></f:facet>
							<h:outputText value="#{orderDet.itemTotal}" />
						</rich:column>
		
					</rich:dataTable>
			</rich:panel>
	</rich:modalPanel>
	
</ui:composition>